package com.atguigu.tingshu.user.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WechatMpConfig {
    @Autowired
    private WechatAccountConfig wechatAccountConfig;

    @Bean
    public WxMaService getWxMaService(){
        //创建对象
        WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
        wxMaDefaultConfig.setAppid(wechatAccountConfig.getAppId());
        wxMaDefaultConfig.setSecret(wechatAccountConfig.getAppSecret());
        wxMaDefaultConfig.setMsgDataFormat("JSON");
        //创建WxMaservice对象
        WxMaServiceImpl wxMaService = new WxMaServiceImpl();
        //给WxMaService 设置配置选项
        wxMaService.setWxMaConfig(wxMaDefaultConfig);
        return wxMaService;
    }
}
